
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta charset="utf-8"></meta>
      <meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
      <title>10.4.&nbsp;Text Functions - Chapter&nbsp;10.&nbsp;Utility Functions</title>
      <link rel="stylesheet" type="text/css" href="../../docbook.css"></link>
      <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,600,300italic"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.css"></link>
      <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/theme/neo.min.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/chunked-base.css"></link>
      <link rel="stylesheet" type="text/css" href="../../css/extra.css"></link><script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script><script src="//cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script><script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/codemirror.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/addon/runmode/runmode.min.js" type="text/javascript"></script><script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.11.0/mode/cypher/cypher.min.js" type="text/javascript"></script><script src="../../javascript/datatable.js" type="text/javascript"></script><script src="../../javascript/colorize.js" type="text/javascript"></script><script src="../../javascript/tabs-for-chunked.js" type="text/javascript"></script><script src="../../javascript/mp-nav.js" type="text/javascript"></script><script src="../../javascript/versionswitcher.js" type="text/javascript"></script><script src="../../javascript/version.js" type="text/javascript"></script><script src="//s3-eu-west-1.amazonaws.com/alpha.neohq.net/docs/new-manual/assets/search.js" type="text/javascript"></script><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></meta>
      <link rel="prev" href="../collection-list-functions/" title="10.3.&nbsp;Collection Functions"></link>
      <link rel="next" href="../math-functions/" title="10.5.&nbsp;Math Functions"></link>
      <link rel="shortcut icon" href="https://neo4j.com/wp-content/themes/neo4jweb/favicon.ico"></link><script>
        $(document).ready(function() {
          CodeMirror.colorize();
          tabTheSource($('body'));
          var $header = $('header').first();
          $header.prepend(
            $('<a href="" id="logo"><img src="https://neo4j.com/wp-content/themes/neo4jweb/assets/images/neo4j-logo-2015.png" alt="Neo4j Logo"></img></a>')
          );
          var $sidebar = $('<div id="sidebar-wrapper"></div>');
          $.get('toc.html', function (d){
            $(d).appendTo($sidebar);
            highlightToc();
            highlightLibraryHeader();
          });
          $sidebar.insertAfter($('header').first());
        });
        </script></head>
   <body>
      <header>
         <div class="searchbox">
            <form id="search-form" class="search" name="search-form" role="search"><input id="search-form-input" name="q" title="search" type="search" lang="en" placeholder="Search Neo4j docs..." aria-label="Search Neo4j documentation" max-length="128" required="required"></input><input id="search-form-button" type="submit" value="Search"></input></form>
         </div>
         <ul class="documentation-library">
            <li><a href="https://neo4j.com/docs/operations-manual/current">Operations Manual</a></li>
            <li><a href="https://neo4j.com/docs/developer-manual/current/">Developer Manual</a></li>
            <li><a href="https://neo4j.com/docs/ogm-manual/current/">OGM Manual</a></li>
            <li><a href="https://neo4j.com/docs/graph-algorithms/current/">Graph Algorithms</a></li>
            <li><a href="https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.4/">APOC</a></li>
            <li><a href="https://neo4j.com/docs/java-reference/current/">Java Reference</a></li>
         </ul>
         <nav id="header-nav"><span class="nav-previous"><a accesskey="p" href="../collection-list-functions/"><span class="fa fa-long-arrow-left" aria-hidden="true"></span>Collection Functions</a></span><span class="nav-current">
               <p class="nav-title hidden">10.4.&nbsp;Text Functions</p></span><span class="nav-next"><a accesskey="n" href="../math-functions/">Math Functions<span class="fa fa-long-arrow-right" aria-hidden="true"></span></a></span></nav>
      </header>
      <div id="search-results" class="hidden"></div>
      <section class="section" id="text-functions">
         <div class="titlepage">
            <div>
               <div>
                  <h2 class="title" style="clear: both"><a class="anchor" href="#text-functions"></a>10.4.&nbsp;Text Functions
                  </h2>
               </div>
            </div>
         </div>
         <p>Cypher has some basic functions to work with text like:</p>
         <div class="itemizedlist">
            <ul class="itemizedlist" style="list-style-type: disc; ">
               <li class="listitem"><code class="literal">split(string, delim)</code></li>
               <li class="listitem"><code class="literal">toLower</code> and <code class="literal">toUpper</code></li>
               <li class="listitem">concatenation with <code class="literal">+</code></li>
               <li class="listitem">and predicates like <code class="literal">CONTAINS, STARTS WITH, ENDS WITH</code> and regular expression matches via <code class="literal">=~</code></li>
            </ul>
         </div>
         <p>A lot of useful functions for string manipulation, comparison, filtering are missing though.
            APOC tries to add many of them.
         </p>
         <section class="section" id="_overview_text_functions">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_overview_text_functions"></a>10.4.1.&nbsp;Overview Text Functions
                     </h3>
                  </div>
               </div>
            </div>
            <div class="informaltable">
               <div class="table" id="d0e11550">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.indexOf(text, lookup, offset=0, to=-1==len)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>find the first occurence of the lookup string in the text, from inclusive, to exclusive,, -1 if not found, null if text is
                                 null.
                              </p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.indexesOf(text, lookup, from=0, to=-1==len)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>finds all occurences of the lookup string in the text, return list, from inclusive, to exclusive, empty list if not found,
                                 null if text is null.
                              </p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.replace(text, regex, replacement)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>replace each substring of the given string that matches the given regular expression with the given replacement.</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.regexGroups(text, regex)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>returns an array containing a nested array for each match. The inner array contains all match groups.</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.join(['text1','text2',&#8230;&#8203;], delimiter)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>join the given strings with the given delimiter.</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.format(text,[params],language)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>sprintf format the string with the params given, and optional param language (default value is 'en').</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.lpad(text,count,delim)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>left pad the string to the given width</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.rpad(text,count,delim)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>right pad the string to the given width</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.random(length, [valid])</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>returns a random string to the specified length</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.capitalize(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>capitalise the first letter of the word</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.capitalizeAll(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>capitalise the first letter of every word in the text</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.decapitalize(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>decapitalize the first letter of the word</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.decapitalizeAll(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>decapitalize the first letter of all words</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.swapCase(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Swap the case of a string</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.camelCase(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Convert a string to camelCase</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.upperCamelCase(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Convert a string to UpperCamelCase</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.snakeCase(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Convert a string to snake-case</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.toUpperCase(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Convert a string to UPPER_CASE</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.charAt(text, index)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Returns the decimal value of the character at the given index</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.code(codepoint)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Returns the unicode character of the given codepoint</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.hexCharAt(text, index)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Returns the hex value string of the character at the given index</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.hexValue(value)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Returns the hex value string of the given value</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.byteCount(text,[charset])</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>return size of text in bytes</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.bytes(text,[charset]) - return bytes of the text</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>apoc.text.toCypher(value, {skipKeys,keepKeys,skipValues,keepValues,skipNull,node,relationship,start,end})</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">tries it&#8217;s best to convert the value to a cypher-property-string</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>apoc.text.base64Encode(text) - Encode a string with Base64</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.base64Decode(text) - Decode Base64 encoded string</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>apoc.text.base64UrlEncode(url) - Encode a url with Base64</p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <p>The <code class="literal">replace</code>, <code class="literal">split</code> and <code class="literal">regexGroups</code> functions work with regular expressions.
            </p>
         </section>
         <section class="section" id="_data_extraction">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_data_extraction"></a>10.4.2.&nbsp;Data Extraction
                     </h3>
                  </div>
               </div>
            </div>
            <div class="informaltable">
               <div class="table" id="d0e11777">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.data.url('url') as {protocol,user,host,port,path,query,file,anchor}</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>turn URL into map structure</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.data.email('email_address') as {personal,user,domain}</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>extract the personal name, user and domain as a map (needs javax.mail jar)</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.data.domain(email_or_url)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><span class="strong"><strong>deprecated</strong></span> returns domain part of the value
                              </p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
         </section>
         <section class="section" id="_text_similarity_functions">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_text_similarity_functions"></a>10.4.3.&nbsp;Text Similarity Functions
                     </h3>
                  </div>
               </div>
            </div>
            <div class="informaltable">
               <div class="table" id="d0e11811">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.distance(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings with the Levenshtein distance algorithm</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.levenshteinDistance(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings with the Levenshtein distance algorithm</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.levenshteinSimilarity(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>calculate the similarity (a value within 0 and 1) between two texts based on Levenshtein distance.</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.hammingDistance(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings with the Hamming distance algorithm</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.jaroWinklerDistance(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings with the Jaro-Winkler distance algorithm</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.sorensenDiceSimilarity(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings with the S&oslash;rensen&#8211;Dice coefficient formula, assuming an English locale</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.sorensenDiceSimilarityWithLanguage(text1, text2, languageTag)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings with the S&oslash;rensen&#8211;Dice coefficient formula, with the provided IETF language tag</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.fuzzyMatch(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>check if 2 words can be matched in a fuzzy way. Depending on the length of the String it will allow more characters that needs
                                 to be edited to match the second String.
                              </p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
         </section>
         <section class="section" id="_phonetic_comparison_functions">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_phonetic_comparison_functions"></a>10.4.4.&nbsp;Phonetic Comparison Functions
                     </h3>
                  </div>
               </div>
            </div>
            <div class="informaltable">
               <div class="table" id="d0e11883">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.phonetic(value)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Compute the US_ENGLISH phonetic soundex encoding of all words of the text value which can be a single string or a list of
                                 strings
                              </p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.doubleMetaphone(value)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Compute the Double Metaphone phonetic encoding of all words of the text value which can be a single string or a list of strings</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.clean(text)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>strip the given string of everything except alpha numeric characters and convert it to lower case.</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">apoc.text.compareCleaned(text1, text2)</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>compare the given strings stripped of everything except alpha numeric characters converted to lower case.</p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <div class="table" id="d0e11920">
               <table class="table" summary="Procedure" border="1">
                  <caption class="table-title">Table&nbsp;10.1.&nbsp;Procedure</caption>
                  <colgroup>
                     <col class="col_1"></col>
                     <col class="col_2"></col>
                  </colgroup>
                  <tbody>
                     <tr>
                        <td style="text-align: left; vertical-align: top; ">
                           <p><code class="literal">apoc.text.phoneticDelta(text1, text2) yield phonetic1, phonetic2, delta</code></p>
                        </td>
                        <td style="text-align: left; vertical-align: top; ">
                           <p>Compute the US_ENGLISH soundex character difference between two given strings</p>
                        </td>
                     </tr>
                  </tbody>
               </table>
            </div>
         </section>
         <section class="section" id="_formatting_text">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_formatting_text"></a>10.4.5.&nbsp;Formatting Text
                     </h3>
                  </div>
               </div>
            </div>
            <p>Format the string with the params given, and optional param language.</p>
            <p><span class="formalpara-title">without language param ('en' default).&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.format('ab%s %d %.1f %s%n',['cd',42,3.14,true]) AS value // abcd 42 3.1 true</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">with language param.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.format('ab%s %d %.1f %s%n',['cd',42,3.14,true],'it') AS value // abcd 42 3,1 true</code></pre><p>
               
            </p>
         </section>
         <section class="section" id="_string_search">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_string_search"></a>10.4.6.&nbsp;String Search
                     </h3>
                  </div>
               </div>
            </div>
            <p>The <code class="literal">indexOf</code> function, provides the fist occurrence of the given <code class="literal">lookup</code> string within the <code class="literal">text</code>, or -1 if not found.
               It can optionally take <code class="literal">from</code> (inclusive) and <code class="literal">to</code> (exclusive) parameters.
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.indexOf('Hello World!', 'World') // 6</code></pre><p>The <code class="literal">indexesOf</code> function, provides all occurrences of the given lookup string within the text, or empty list if not found.
               It can optionally take <code class="literal">from</code> (inclusive) and <code class="literal">to</code> (exclusive) parameters.
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.indexesOf('Hello World!', 'o',2,9) // [4,7]</code></pre><p>If you want to get a substring starting from your index match, you can use this</p>
            <p><span class="formalpara-title">returns <code class="literal">World!</code>&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">WITH 'Hello World!' as text, length(text) as len
WITH text, len, apoc.text.indexOf(text, 'World',3) as index
RETURN substring(text, case index when -1 then len-1 else index end, len);</code></pre><p>
               
            </p>
         </section>
         <section class="section" id="_regular_expressions">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_regular_expressions"></a>10.4.7.&nbsp;Regular Expressions
                     </h3>
                  </div>
               </div>
            </div>
            <p><span class="formalpara-title">will return 'HelloWorld'.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.replace('Hello World!', '[^a-zA-Z]', '')</code></pre><p>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.regexGroups('abc &lt;link xxx1&gt;yyy1&lt;/link&gt; def &lt;link xxx2&gt;yyy2&lt;/link&gt;','&lt;link (\\w+)&gt;(\\w+)&lt;/link&gt;') AS result

// [["&lt;link xxx1&gt;yyy1&lt;/link&gt;", "xxx1", "yyy1"], ["&lt;link xxx2&gt;yyy2&lt;/link&gt;", "xxx2", "yyy2"]]</code></pre></section>
         <section class="section" id="_split_and_join">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_split_and_join"></a>10.4.8.&nbsp;Split and Join
                     </h3>
                  </div>
               </div>
            </div>
            <p><span class="formalpara-title">will split with the given regular expression return ['Hello', 'World'].&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.split('Hello   World', ' +')</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">will return 'Hello World'.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.join(['Hello', 'World'], ' ')</code></pre><p>
               
            </p>
         </section>
         <section class="section" id="_data_cleaning">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_data_cleaning"></a>10.4.9.&nbsp;Data Cleaning
                     </h3>
                  </div>
               </div>
            </div>
            <p><span class="formalpara-title">will return 'helloworld'.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.clean('Hello World!')</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">will return <code class="literal">true</code>.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.compareCleaned('Hello World!', '_hello-world_')</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">will return only 'Hello World!'.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">UNWIND ['Hello World!', 'hello worlds'] as text
RETURN apoc.text.filterCleanMatches(text, 'hello_world') as text</code></pre><p>
               
            </p>
            <p>The clean functionality can be useful for cleaning up slightly dirty text data with inconsistent formatting for non-exact
               comparisons.
            </p>
            <p>Cleaning will strip the string of all non-alphanumeric characters (including spaces) and convert it to lower case.</p>
         </section>
         <section class="section" id="_case_change_functions">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_case_change_functions"></a>10.4.10.&nbsp;Case Change Functions
                     </h3>
                  </div>
               </div>
            </div>
            <section class="section" id="_capitalise_the_first_letter_of_the_word_with_literal_capitalize_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_capitalise_the_first_letter_of_the_word_with_literal_capitalize_literal"></a>10.4.10.1.&nbsp;Capitalise the first letter of the word with <code class="literal">capitalize</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.capitalize("neo4j") // "Neo4j"</code></pre></section>
            <section class="section" id="_capitalise_the_first_letter_of_every_word_in_the_text_with_literal_capitalizeall_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_capitalise_the_first_letter_of_every_word_in_the_text_with_literal_capitalizeall_literal"></a>10.4.10.2.&nbsp;Capitalise the first letter of every word in the text with <code class="literal">capitalizeAll</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.capitalizeAll("graph database") // "Graph Database"</code></pre></section>
            <section class="section" id="_decapitalize_the_first_letter_of_the_string_with_literal_decapitalize_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_decapitalize_the_first_letter_of_the_string_with_literal_decapitalize_literal"></a>10.4.10.3.&nbsp;Decapitalize the first letter of the string with <code class="literal">decapitalize</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.decapitalize("Graph Database") // "graph Database"</code></pre></section>
            <section class="section" id="_decapitalize_the_first_letter_of_all_words_with_literal_decapitalizeall_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_decapitalize_the_first_letter_of_all_words_with_literal_decapitalizeall_literal"></a>10.4.10.4.&nbsp;Decapitalize the first letter of all words with <code class="literal">decapitalizeAll</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.decapitalizeAll("Graph Databases") // "graph databases"</code></pre></section>
            <section class="section" id="_swap_the_case_of_a_string_with_literal_swapcase_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_swap_the_case_of_a_string_with_literal_swapcase_literal"></a>10.4.10.5.&nbsp;Swap the case of a string with <code class="literal">swapCase</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.swapCase("Neo4j") // nEO4J</code></pre></section>
            <section class="section" id="_convert_a_string_to_lower_camelcase_with_literal_camelcase_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_convert_a_string_to_lower_camelcase_with_literal_camelcase_literal"></a>10.4.10.6.&nbsp;Convert a string to lower camelCase with <code class="literal">camelCase</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.camelCase("FOO_BAR");    // "fooBar"
RETURN apoc.text.camelCase("Foo bar");    // "fooBar"
RETURN apoc.text.camelCase("Foo22 bar");  // "foo22Bar"
RETURN apoc.text.camelCase("foo-bar");    // "fooBar"
RETURN apoc.text.camelCase("Foobar");     // "foobar"
RETURN apoc.text.camelCase("Foo$$Bar");   // "fooBar"</code></pre></section>
            <section class="section" id="_convert_a_string_to_uppercamelcase_with_literal_uppercamelcase_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_convert_a_string_to_uppercamelcase_with_literal_uppercamelcase_literal"></a>10.4.10.7.&nbsp;Convert a string to UpperCamelCase with <code class="literal">upperCamelCase</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.upperCamelCase("FOO_BAR");   // "FooBar"
RETURN apoc.text.upperCamelCase("Foo bar");   // "FooBar"
RETURN apoc.text.upperCamelCase("Foo22 bar"); // "Foo22Bar"
RETURN apoc.text.upperCamelCase("foo-bar");   // "FooBar"
RETURN apoc.text.upperCamelCase("Foobar");    // "Foobar"
RETURN apoc.text.upperCamelCase("Foo$$Bar");  // "FooBar"</code></pre></section>
            <section class="section" id="_convert_a_string_to_snake_case_with_literal_snakecase_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_convert_a_string_to_snake_case_with_literal_snakecase_literal"></a>10.4.10.8.&nbsp;Convert a string to snake-case with <code class="literal">snakeCase</code></h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.snakeCase("test Snake Case"); // "test-snake-case"
RETURN apoc.text.snakeCase("FOO_BAR");         // "foo-bar"
RETURN apoc.text.snakeCase("Foo bar");         // "foo-bar"
RETURN apoc.text.snakeCase("fooBar");          // "foo-bar"
RETURN apoc.text.snakeCase("foo-bar");         // "foo-bar"
RETURN apoc.text.snakeCase("Foo bar");         // "foo-bar"
RETURN apoc.text.snakeCase("Foo  bar");        // "foo-bar"</code></pre></section>
            <section class="section" id="_convert_a_string_to_upper_case_with_touppercase">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_convert_a_string_to_upper_case_with_touppercase"></a>10.4.10.9.&nbsp;Convert a string to UPPER_CASE with `toUpperCase
                        </h4>
                     </div>
                  </div>
               </div><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.toUpperCase("test upper case"); // "TEST_UPPER_CASE"
RETURN apoc.text.toUpperCase("FooBar");          // "FOO_BAR"
RETURN apoc.text.toUpperCase("fooBar");          // "FOO_BAR"
RETURN apoc.text.toUpperCase("foo-bar");         // "FOO_BAR"
RETURN apoc.text.toUpperCase("foo--bar");        // "FOO_BAR"
RETURN apoc.text.toUpperCase("foo$$bar");        // "FOO_BAR"
RETURN apoc.text.toUpperCase("foo 22 bar");      // "FOO_22_BAR"</code></pre></section>
         </section>
         <section class="section" id="_base64_de_and_encoding">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_base64_de_and_encoding"></a>10.4.11.&nbsp;Base64 De- and Encoding
                     </h3>
                  </div>
               </div>
            </div>
            <p>Encode or decode a string in base64 or base64Url</p>
            <p><span class="formalpara-title">EncodeBase64.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.base64Encode("neo4j") // bmVvNGo=</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">DecodeBase64.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.base64Decode("bmVvNGo=") // neo4j</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">EncodeBase64Url.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.base64EncodeUrl("http://neo4j.com/?test=test") // aHR0cDovL25lbzRqLmNvbS8_dGVzdD10ZXN0</code></pre><p>
               
            </p>
            <p><span class="formalpara-title">DecodeBase64Url.&nbsp;</span>
               
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.base64DecodeUrl("aHR0cDovL25lbzRqLmNvbS8_dGVzdD10ZXN0") // http://neo4j.com/?test=test</code></pre><p>
               
            </p>
         </section>
         <section class="section" id="_random_string">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_random_string"></a>10.4.12.&nbsp;Random String
                     </h3>
                  </div>
               </div>
            </div>
            <p>You can generate a random string to a specified length by calling <code class="literal">apoc.text.random</code> with a length parameter and optional string of valid characters.
            </p>
            <p>The <code class="literal">valid</code> parameter will accept the following regex patterns, alternatively you can provide a string of letters and/or characters.
            </p>
            <div class="informaltable">
               <div class="table" id="d0e12182">
                  <table class="informaltable" border="1">
                     <colgroup>
                        <col class="col_1"></col>
                        <col class="col_2"></col>
                     </colgroup>
                     <tbody>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">Pattern</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Description</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">A-Z</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>A-Z in uppercase</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">a-z</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>A-Z in lowercase</p>
                           </td>
                        </tr>
                        <tr>
                           <td style="text-align: left; vertical-align: top; ">
                              <p><code class="literal">0-9</code></p>
                           </td>
                           <td style="text-align: left; vertical-align: top; ">
                              <p>Numbers 0-9 inclusive</p>
                           </td>
                        </tr>
                     </tbody>
                  </table>
               </div>
            </div>
            <p>The following call will return a random string including uppercase letters, numbers and <code class="literal">.</code> and <code class="literal">$</code> characters.
            </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.random(10, "A-Z0-9.$")</code></pre></section>
         <section class="section" id="_text_similarity_functions_2">
            <div class="titlepage">
               <div>
                  <div>
                     <h3 class="title"><a class="anchor" href="#_text_similarity_functions_2"></a>10.4.13.&nbsp;Text Similarity Functions
                     </h3>
                  </div>
               </div>
            </div>
            <section class="section" id="_compare_the_strings_with_the_levenshtein_distance">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_compare_the_strings_with_the_levenshtein_distance"></a>10.4.13.1.&nbsp;Compare the  strings with the Levenshtein distance
                        </h4>
                     </div>
                  </div>
               </div>
               <p>Compare the given strings with the <code class="literal">StringUtils.distance(text1, text2)</code> method (Levenshtein).
               </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.distance("Levenshtein", "Levenstein") // 1</code></pre></section>
            <section class="section" id="_compare_the_given_strings_with_the_s&oslash;rensen_dice_coefficient_formula">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_compare_the_given_strings_with_the_s&oslash;rensen_dice_coefficient_formula"></a>10.4.13.2.&nbsp;Compare the given strings with the S&oslash;rensen&#8211;Dice coefficient formula.
                        </h4>
                     </div>
                  </div>
               </div>
               <p><span class="formalpara-title">computes the similarity assuming Locale.ENGLISH.&nbsp;</span>
                  
               </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.sorensenDiceSimilarity("belly", "jolly") // 0.5</code></pre><p>
                  
               </p>
               <p><span class="formalpara-title">computes the similarity with an explicit locale.&nbsp;</span>
                  
               </p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.sorensenDiceSimilarityWithLanguage("hal&#305;m", "halim", "tr-TR") // 0.5</code></pre><p>
                  
               </p>
            </section>
            <section class="section" id="_check_if_2_words_can_be_matched_in_a_fuzzy_way_with_literal_fuzzymatch_literal">
               <div class="titlepage">
                  <div>
                     <div>
                        <h4 class="title"><a class="anchor" href="#_check_if_2_words_can_be_matched_in_a_fuzzy_way_with_literal_fuzzymatch_literal"></a>10.4.13.3.&nbsp;Check if 2 words can be matched in a fuzzy way with <code class="literal">fuzzyMatch</code></h4>
                     </div>
                  </div>
               </div>
               <p>Depending on the length of the String it will allow more characters that needs to be edited to match the second String.</p><pre class="programlisting highlight"><code data-lang="cypher">RETURN apoc.text.fuzzyMatch("The", "the") // true</code></pre></section>
         </section>
      </section>
      <footer><script type="text/javascript">
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
          //Allow Linker
          ga('create', 'UA-1192232-34','auto', {'allowLinker': true});
          ga('send', 'pageview');
          // Load the plugin.
          ga('require', 'linker');
          // Define which domains to autoLink.
          ga('linker:autoLink', ['neo4j.org','neo4j.com','neotechnology.com','graphdatabases.com','graphconnect.com']);
        </script><script type="text/javascript">
          document.write(unescape("%3Cscript src='//munchkin.marketo.net/munchkin.js' type='text/javascript'%3E%3C/script%3E"));
        </script><script>Munchkin.init('773-GON-065');</script></footer>
   </body>
</html>